home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / bsearch.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  6KB  |  181 lines

  1. /*
  2.     GWAda Development Environment for 386/486 PCs   
  3.     Copyright (C) 1993, Arthur Vargas Lopes  & Michael Bliss Feldman
  4.                         vlopes@vortex.ufrgs.br mfeldman@seas.gwu.edu
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; version 2 of the License.    
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /* Bsearch.c */
  21.  
  22.  
  23.  
  24. int IS_KEYWORD(char *s)
  25. {
  26.  
  27.     typedef struct {
  28.         int  code;
  29.         char *key;
  30.     } KEY_WORD;
  31.  
  32.     static KEY_WORD keywords[NO_KEYWORDS] = {
  33.          {XABORT               ,"ABORT"}
  34.         ,{XABS                 ,"ABS"}
  35.         ,{XACCEPT              ,"ACCEPT"}
  36.         ,{XACCESS              ,"ACCESS"}
  37.         ,{XALL                 ,"ALL"}
  38.         ,{XAND                 ,"AND"}
  39.         ,{XARRAY               ,"ARRAY"}
  40.         ,{XAT                  ,"AT"}
  41.         ,{XBEGIN               ,"BEGIN"}
  42.         ,{XBODY                ,"BODY"}
  43.         ,{XCASE                ,"CASE"}
  44.         ,{XCONSTANT            ,"CONSTANT"}
  45.         ,{XDECLARE             ,"DECLARE"}
  46.         ,{XDELAY               ,"DELAY"}
  47.         ,{XDELTA               ,"DELTA"}
  48.         ,{XDIGITS              ,"DIGITS"}
  49.         ,{XDO                  ,"DO"}
  50.         ,{XELSE                ,"ELSE"}
  51.         ,{XELSIF               ,"ELSIF"}
  52.         ,{XEND                 ,"END"}
  53.         ,{XENTRY               ,"ENTRY"}
  54.         ,{XEXCEPTION           ,"EXCEPTION"}
  55.         ,{XEXIT                ,"EXIT"}
  56.         ,{XFOR                 ,"FOR"}
  57.         ,{XFUNCTION            ,"FUNCTION"}
  58.         ,{XGENERIC             ,"GENERIC"}
  59.         ,{XGOTO                ,"GOTO"}
  60.         ,{XIF                  ,"IF"}
  61.         ,{XIN                  ,"IN"}
  62.         ,{XIS                  ,"IS"}
  63.         ,{XLIMITED             ,"LIMITED"}
  64.         ,{XLOOP                ,"LOOP"}
  65.         ,{XMOD                 ,"MOD"}
  66.         ,{XNEW                 ,"NEW"}
  67.         ,{XNOT                 ,"NOT"}
  68.         ,{XNULL                ,"NULL"}
  69.         ,{XOF                  ,"OF"}
  70.         ,{XOR                  ,"OR"}
  71.         ,{XOTHERS              ,"OTHERS"}
  72.         ,{XOUT                 ,"OUT"}
  73.         ,{XPACKAGE             ,"PACKAGE"}
  74.         ,{XPRAGMA              ,"PRAGMA"}
  75.         ,{XPRIVATE             ,"PRIVATE"}
  76.         ,{XPROCEDURE           ,"PROCEDURE"}
  77.         ,{XRAISE               ,"RAISE"}
  78.         ,{XRANGE               ,"RANGE"}
  79.         ,{XRECORD              ,"RECORD"}
  80.         ,{XREM                 ,"REM"}
  81.         ,{XRENAMES             ,"RENAMES"}
  82.         ,{XRETURN              ,"RETURN"}
  83.         ,{XREVERSE             ,"REVERSE"}
  84.         ,{XSELECT              ,"SELECT"}
  85.         ,{XSEPARATE            ,"SEPARATE"}
  86.         ,{XSUBTYPE             ,"SUBTYPE"}
  87.         ,{XTASK                ,"TASK"}
  88.         ,{XTERMINATE           ,"TERMINATE"}
  89.         ,{XTHEN                ,"THEN"}
  90.         ,{XTYPE                ,"TYPE"}
  91.         ,{XUSE                 ,"USE"}
  92.         ,{XWHEN                ,"WHEN"}
  93.         ,{XWHILE               ,"WHILE"}
  94.         ,{XWITH                ,"WITH"}
  95.         ,{XXOR                 ,"XOR"}
  96.         };
  97.  
  98.     int left, high, med, r;
  99.     left = 0;
  100.     high = NO_KEYWORDS - 1;
  101.     while (left <= high)  {
  102.         med = (high + left) / 2;
  103.         if (!(r = strcmp(s,keywords[med].key)))
  104.             return keywords[med].code;
  105.         if (r < 0)
  106.             high = med - 1;
  107.         else
  108.             left = med + 1;
  109.         }
  110.     return 0;
  111. }
  112.  
  113.  
  114. int IS_ATT(char *s)
  115. {
  116.     typedef struct {
  117.         int  code;
  118.         char *key;
  119.     } KEY_ATT;
  120.  
  121.     int left, high, med, r;
  122.  
  123.     static KEY_ATT keyatts[40] = {
  124.          {XA_ADDRESS             ,"ADDRESS"}
  125.         ,{XA_AFT                 ,"AFT"}
  126.         ,{XA_BASE                ,"BASE"}
  127.         ,{XA_CALLABLE            ,"CALLABLE"}
  128.         ,{XA_CONSTRAINED         ,"CONSTRAINED"}
  129.         ,{XA_COUNT               ,"COUNT"}
  130.         ,{XA_DELTA               ,"DELTA"}
  131.         ,{XA_DIGITS              ,"DIGITS"}
  132.         ,{XA_EMAX                ,"EMAX"}
  133.         ,{XA_EPSILON             ,"EPSILON"}
  134.         ,{XA_FIRST               ,"FIRST"}
  135.         ,{XA_FIRST_BIT           ,"FIRST_BIT"}
  136.         ,{XA_FORE                ,"FORE"}
  137.         ,{XA_IMAGE               ,"IMAGE"}
  138.         ,{XA_LARGE               ,"LARGE"}
  139.         ,{XA_LAST                ,"LAST"}
  140.         ,{XA_LAST_BIT            ,"LAST_BIT"}
  141.         ,{XA_LENGTH              ,"LENGTH"}
  142.         ,{XA_MACHINE_EMAX        ,"MACHINE_EMAX"}
  143.         ,{XA_MACHINE_EMIN        ,"MACHINE_EMIN"}
  144.         ,{XA_MACHINE_MANTISSA    ,"MACHINE_MANTISSA"}
  145.         ,{XA_MACHINE_OVERFLOWS   ,"MACHINE_OVERFLOWS"}
  146.         ,{XA_MACHINE_RADIX       ,"MACHINE_RADIX"}
  147.         ,{XA_MACHINE_ROUNDS      ,"MACHINE_ROUNDS"}
  148.         ,{XA_MANTISSA            ,"MANTISSA"}
  149.         ,{XA_POS                 ,"POS"}
  150.         ,{XA_POSITION            ,"POSITION"}
  151.         ,{XA_PRED                ,"PRED"}
  152.         ,{XA_RANGE               ,"RANGE"}
  153.         ,{XA_SAFE_EMAX           ,"SAFE_EMAX"}
  154.         ,{XA_SAFE_LARGE          ,"SAFE_LARGE"}
  155.         ,{XA_SAFE_SMALL          ,"SAFE_SMALL"}
  156.         ,{XA_SIZE                ,"SIZE"}
  157.         ,{XA_SMALL               ,"SMALL"}
  158.         ,{XA_STORAGE_SIZE        ,"STORAGE_SIZE"}
  159.         ,{XA_SUCC                ,"SUCC"}
  160.         ,{XA_TERMINATED          ,"TERMINATED"}
  161.         ,{XA_VAL                 ,"VAL"}
  162.         ,{XA_VALUE               ,"VALUE"}
  163.         ,{XA_WIDTH               ,"WIDTH"}
  164.         };
  165.  
  166.     left = 0;
  167.     high = NO_ATTS - 1;
  168.  
  169.     while (left <= high)  {
  170.         med = (high + left) / 2;
  171.         if (!(r = strcmp(s,keyatts[med].key)))
  172.             return keyatts[med].code;
  173.         if (r < 0)
  174.             high = med - 1;
  175.         else
  176.             left = med + 1;
  177.         }
  178.     return 0;
  179. }
  180.  
  181.